
# source node has a net positive flow (+1);
# simplification, no need to consider incoming flow into source

subject to src_flow:
sum {(source,j,k,l) in ARCS} itinerary[source,j,k,l]
 - sum {(m,source,n,o) in ARCS} itinerary[m,source,n,o] = 1;


# destination node has a net negative flow (-1)
# possible simplification, no need to consider outgoing flow from dest
# doesn't seem to work sometimes

subject to dest_flow:
#sum {(m,dest,n,o) in ARCS} itinerary[m,dest,n,o] = 1;
sum {(dest,j,k,l) in ARCS} itinerary[dest,j,k,l]
- sum {(m,dest,n,o) in ARCS} itinerary[m,dest,n,o] = -1;


# all other nodes have net zero flow

subject to balance_flow {i in nodes diff {source, dest}}:
sum {(i,j,k,l) in ARCS} itinerary[i,j,k,l]
- sum {(m,i,n,o) in ARCS} itinerary[m,i,n,o] = 0;


# preferred departure day

subject to c_depart_day:
#sum { j in src_connectd_nodes, k in src_outgoing_flights } itinerary[source,j,k,1] = 1;
sum {day in {depart_day_rng_lb..depart_day_rng_ub}} sum { (source,j,k,1) in ARCS } itinerary[source,j,k,day] = 1;


# for every intermediate node, departure must be after arrival
# TODO: enforce minimum layover
subject to depart_follows_arrive {i in nodes diff {source, dest}}:
sum {(i,j,k,l) in ARCS} itinerary[i,j,k,l]*(24*(l-1) + floor(depart_tm[k]/100) + (depart_tm[k] mod 100)/60)
- sum {(o,i,m,n) in ARCS} itinerary[o,i,m,n]*(24*(n + arrive_day[m] - 1) + floor(arrive_tm[m]/100) + (arrive_tm[m] mod 100)/60) >= 0;

